<!DOCTYPE html>
<html>

<body>

    <h1>JavaScript 值传递</h1>
    <script>
        console.log('===========1==============');

        var t1 = new Object();
        var t2 = t1;
        t2.name ="t1";
        t2 = new Object();      //本质为t2的指针指向了一个新空间
        console.log(t1.name);   //输出t1
        console.log(t2.name);   //输出undefined

        console.log('===========2==============');

        var t3 = new Object();
        function change(obj){
            obj.name = "lalala";
        }
        change(t3);
        console.log(t3.name);  //输出了lalala;t1指向的对象多了一个属性

        console.log('===========3==============');

        var t4 = new Object();
        function change(obj){
            obj.name = "t1";
            obj = new Object();
            obj.name = "new t1";
        }
        change(t4);
        console.log(t4.name); //输出t1;t1.name仍然是‘‘t1’’，再进行obj = new Object（）时候，因为栈内存中数据的改变，这里的obj最终指向的对象不是t1指向的对象了，就函数内部再也操作不到t1一开始指向的对象了

        console.log('===========4==============');
        /*变量本身是按值传递，因此改变内部变量（就只改变t5、t6），外部变量不会有改变*/
        var t5 = new Object();
        var t6 = t5;
        t6.name ="t1";
        t6 = new Object();
        console.log(t5.name);  //输出t1
        console.log(t6.name);  //输出undefined

    </script>
</body>

</html>